﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PPTHelper.Decode
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
      

            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            Rectangle rectangle = new Rectangle();
            rectangle.Fill = Brushes.Red;
            rectangle.Width = 200;
            rectangle.Height = 30;

            this.stackPanel.Children.Add(rectangle);


            ObjectAnimationUsingKeyFrames animate = new ObjectAnimationUsingKeyFrames();

            Storyboard storyboard = new Storyboard();
            //Storyboard.SetTargetName(animate, "button");
            Storyboard.SetTargetProperty(storyboard, new PropertyPath("Visibility"));
            Storyboard.SetTarget(animate, rectangle);

            DiscreteObjectKeyFrame discrete = new DiscreteObjectKeyFrame();
            discrete.KeyTime = TimeSpan.FromMilliseconds(2000);
            discrete.Value = Visibility.Hidden;

            animate.KeyFrames.Add(discrete);

            storyboard.Children.Add(animate);
            storyboard.Begin();

        }
        private void button_Click1(object sender, RoutedEventArgs e)
        {
            DoubleAnimation animate = new DoubleAnimation();
            animate.From = 0.0;
            animate.To = 500.0;
            animate.Duration = TimeSpan.FromSeconds(2);

            Storyboard storyboard = new Storyboard();
            Storyboard.SetTargetProperty(storyboard, new PropertyPath("(Canvas.Left)"));
            Storyboard.SetTarget(animate, this.button);

            storyboard.Children.Add(animate);
            storyboard.Begin();

        }

        /// <summary>
        /// 利用Canvas移动坐标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DoubleAnimationUsingKeyFrames animate = new DoubleAnimationUsingKeyFrames();

            Storyboard storyboard = new Storyboard();
            //Storyboard.SetTargetName(animate, "button");
            Storyboard.SetTargetProperty(storyboard, new PropertyPath("(Canvas.Left)"));
            Storyboard.SetTarget(animate, this.button);

            LinearDoubleKeyFrame linear = new LinearDoubleKeyFrame();
            linear.KeyTime = TimeSpan.FromMilliseconds(2000);
            linear.Value = 500.0;

            animate.KeyFrames.Add(linear);

            storyboard.Children.Add(animate);
            storyboard.Begin();
        }

        /// <summary>
        /// 通过变换移动坐标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            DoubleAnimation animation = new DoubleAnimation();
            Storyboard storyboard = new Storyboard();

            var translate = new TranslateTransform();
            button.RenderTransform = translate;

            Storyboard.SetTarget(storyboard, translate);
            Storyboard.SetTargetProperty(storyboard, new PropertyPath(TranslateTransform.XProperty));

            animation.Duration = TimeSpan.FromMilliseconds(1000);
            animation.From = 0;
            animation.To = 500;

            //translate.BeginAnimation(TranslateTransform.XProperty, animation);

            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
    }
}
